

package com.hazelcast.instance.impl.executejar;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.function.Predicate;
import java.util.jar.JarFile;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;

final class JarScanner {
    private JarScanner() {
    }

    static List<String> findClassFiles(JarFile jarFile, String className) {
        String filename = className + ".class";
        return jarFile.stream().map(ZipEntry::getName).map(Paths::get).filter(byFilename(filename)).map(Path::toString).collect(Collectors.toList());
    }

    private static Predicate<Path> byFilename(String filename) {
        // ignore the package name because the HZ classes could be shaded in the jar
        return path -> path.getFileName().toString().equals(filename);
    }
}
